Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
contentful-sdk-core
Advanced tools
The contentful-sdk-core npm package provides core functionalities for interacting with the Contentful Content Delivery API. It is designed to be a foundational library that other Contentful SDKs can build upon, offering utilities for making HTTP requests, handling responses, and managing errors.
HTTP Client
This feature allows you to create an HTTP client configured to interact with the Contentful API. The code sample demonstrates how to create an HTTP client using Axios and make a GET request to fetch entries.
const { createHttpClient } = require('contentful-sdk-core');
const axios = require('axios');
const httpClient = createHttpClient(axios, {
accessToken: 'your_access_token',
space: 'your_space_id'
});
httpClient.get('/entries')
.then(response => console.log(response.data))
.catch(error => console.error(error));
Error Handling
This feature provides a standardized way to handle errors that occur during API requests. The code sample shows how to use the errorHandler function to manage errors from a GET request.
const { createHttpClient, errorHandler } = require('contentful-sdk-core');
const axios = require('axios');
const httpClient = createHttpClient(axios, {
accessToken: 'your_access_token',
space: 'your_space_id'
});
httpClient.get('/entries')
.then(response => console.log(response.data))
.catch(error => errorHandler(error));
Request Configuration
This feature allows you to configure various aspects of the HTTP requests, such as headers and query parameters. The code sample demonstrates how to add custom headers to the HTTP client.
const { createHttpClient } = require('contentful-sdk-core');
const axios = require('axios');
const httpClient = createHttpClient(axios, {
accessToken: 'your_access_token',
space: 'your_space_id',
headers: {
'X-Custom-Header': 'customValue'
}
});
httpClient.get('/entries')
.then(response => console.log(response.data))
.catch(error => console.error(error));
The 'contentful' package is a higher-level SDK that builds on top of contentful-sdk-core. It provides more abstracted and user-friendly methods for interacting with the Contentful API, such as fetching entries, assets, and content types. It is more feature-rich and easier to use for common tasks compared to contentful-sdk-core.
The 'contentful-management' package is another higher-level SDK that focuses on the Contentful Management API. It allows you to manage content types, entries, assets, and more. Like the 'contentful' package, it builds on top of contentful-sdk-core but is tailored for content management tasks rather than content delivery.
While 'axios' is a general-purpose HTTP client and not specific to Contentful, it is often used in conjunction with contentful-sdk-core to make HTTP requests. It provides a flexible and powerful API for making HTTP requests, handling responses, and managing errors, similar to the core functionalities provided by contentful-sdk-core.
This package contains some core modules and utilities used by both the contentful.js and contentful-management.js SDKs.
The vendor-browser
and vendor-node
directories contain a vendored build of axios which are used respectively on the standalone browser build and on the published npm package.
Axios is vendored because it expects a native or polyfilled implementation of promises. In this particular case, we vendor axios using babel, which uses the babel-plugin-transform-runtime to transform any usage of promises to requires to babel-runtime/core-js/promise
.
Axios can be vendored with npm run vendor:browser
and npm run vendor:node
.
The browser vendored version runs on top of the standalone Axios browser version which is already optimized for this use case (it's not a good idea to try and run babel on top of the normal axios commonjs package as it produces an unnecessarily large file)
Because of this, the follow-redirects dependency of axios needs to be a dependency on this package as well, otherwise it won't be installed.
The additional npm run vendor:version
task is unrelated to axios vendoring and is used to build the library version into the code, to avoid having to bundle code for reading a json file in the browser build.
According to this issue in the future lodash and core-js will be incompatible.
This means one of two things:
Given that by the time lodash becomes incompatible with core-js node.js 0.10 will already be officially unsupported, the second approach might be the correct one.
FAQs
Core modules for the Contentful JS SDKs
The npm package contentful-sdk-core receives a total of 630,748 weekly downloads. As such, contentful-sdk-core popularity was classified as popular.
We found that contentful-sdk-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.